package com.funcourse.demo.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import java.util.ArrayList;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class UserWithScore extends User {

  Integer totalScore = 0;
  Integer ranking = -1;
  List<Score> scoreDetails = new ArrayList<>();
  Integer myOnGoingQuestionNumber = -1;

  public UserWithScore(User source){
    super();
    BeanUtils.copyProperties(source,this);
    clearPrivateData();
  }

  public boolean addSocre(Score score) {
    if (!scoreDetails.contains(score)) {
      scoreDetails.add(score);
      totalScore += score.getScore();
      myOnGoingQuestionNumber = score.questionNumber;
      return true;
    } else {
      return false;
    }
  }


  @Data
  @NoArgsConstructor
  @AllArgsConstructor
  public static class Score {

    Integer questionNumber = -1;
    Integer score = 0;
    @ApiModelProperty("单选题作答选项")
    Integer choiceNumber;
    /**
     * 多选题的回答
     */
    @ApiModelProperty("多选题作答选项")
    List<Integer> multiChoiceNumbers;

    @ApiModelProperty("填空作答选项")
    List<String> answers;
    @Override
    public boolean equals(Object obj){
      if(null == obj){
        return false;
      }
      if(! (obj instanceof Score)){
        return false;
      }
      if(null == this.questionNumber){
        return false;
      }
      return this.questionNumber.equals(((Score)obj).questionNumber);
    }
  }
  @Override
  public boolean equals(Object obj){
    if(null == obj){
      return false;
    }
    if(! (obj instanceof User)){
      return false;
    }
    if(null == this.id){
      return false;
    }
    return this.id.equals(((User)obj).id);
  }
}
